package com.ouyy.volunteerservice.volunteer.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ouyy.volunteerservice.volunteer.domain.po.VolunteerRegistration;
import com.ouyy.volunteerservice.volunteer.mapper.VolunteerRegistrationMapper;
import com.ouyy.volunteerservice.volunteer.service.VolunteerRegistrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VolunteerRegistrationServiceImpl extends ServiceImpl<VolunteerRegistrationMapper, VolunteerRegistration>
        implements VolunteerRegistrationService {

    @Autowired
    private VolunteerRegistrationMapper registrationMapper;

    @Override
    public VolunteerRegistration findByActivityIdAndVolunteerId(Integer activityId, Integer volunteerId) {
        QueryWrapper<VolunteerRegistration> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("activity_id", activityId)  // activityId 字段等于传入的 activityId
                .eq("volunteer_id", volunteerId); // volunteerId 字段等于传入的 volunteerId
        // 查询结果
        return this.getOne(queryWrapper); // 返回第一条匹配的记录
    }

    @Override
    public List<VolunteerRegistration> findByVolunteerId(Integer volunteerId) {
        QueryWrapper<VolunteerRegistration> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("volunteer_id", volunteerId); // 条件查询

        return this.list(queryWrapper); // 返回符合条件的所有记录
    }

}
